public class Solution2287 {
    public int rearrangeCharacters(String s, String target) {
        char[] f=new char[26];
        for (char c : s.toCharArray()) {
            f[c-'a']++;
        }
        char[] g=new char[26];
        for (char c : target.toCharArray()) {
            g[c-'a']++;
        }
        int ans=Integer.MAX_VALUE;
        for (int i = 0; i < 26; i++) {
            if (g[i]!=0){
                ans=Math.min(ans,f[i]/g[i]);
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution2287().rearrangeCharacters("ilovecodingonleetcode","code"));
    }
}
